package com.javabasic.gui.javafx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.apache.commons.lang3.StringUtils;

/**
 * @author mir.xiong
 * @version 1.0
 * @description
 * @see
 * @since Created by work on 2022/10/8 22:54
 * add VMoption:
 * --module-path "/Users/mir/javatools/javafx-sdk-19/lib" --add-modules javafx.controls,javafx.fxml
 */
public class HelloFx extends Application {

    @Override
    public void start(Stage stage) throws Exception {

        stage.setTitle("第一个javaFx应用");

        stage.setWidth(500);
        stage.setHeight(500);


        TextArea contentEdit = new TextArea();
        contentEdit.setDisable(true);

        TextField textField = new TextField();

        Button button = new Button("发送");

        button.setOnAction(event -> {
            CharSequence characters = textField.getCharacters();
            System.out.println(characters);


            String text = contentEdit.getText();
            if (StringUtils.isNotBlank(text)) {
                characters = "\n" + characters;
            }
            text += characters;

            contentEdit.setText(text);

            textField.clear();
        });

        HBox hBox = new HBox();
        hBox.getChildren().addAll(textField, button,contentEdit);


        Scene scene = new Scene(hBox, 500, 50);


        stage.setScene(scene);


        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
